/**
 * 预支账户管理
 */
app.controller('formSelfCtrl', ['$scope', '$http', function FormSelfController($scope, $http){
	/*
	 * 显示单选弹出框
	 * modalKey 弹出框唯一KEY
	 * type 类型，1表单用2子列表用3其它
	 * code 关联的字段编码
	 * subIndex 所在的子列表序号
	 */
	$scope.showModalRadio = function(modalKey, type, code, subIndex, conditionsDefault) {
		console.log('code',code);
		if(code == '_ys_vyhzhmc'){
			var accountType = $scope.valueMap["accountType"]; // 账户性质(0员工账户、1合作商账户)
			if(accountType==undefined || accountType==null || accountType==''){
				layer.msg("请先选择账户性质！");
				return;
			}
			if(accountType=='0'){//0员工账户
				modalKey = 'TS_UserBankInfoGzFk';
				type = 3;
				//layui.YsModal.init({modalKey: 'TS_UserBankInfoGzFk', colCode: "vyhzhmc", parentObj: window.formObj, extraData: {useIn: 'accountTypeByUser'}});
			}else{//1合作商账户
				modalKey = 'TB_PartnerBankInfoFk';
				type = 3;
				//layui.YsModal.init({modalKey: 'TB_PartnerBankInfoFk', colCode: "vyhzhmc", parentObj: window.formObj, extraData: {useIn: 'accountTypeByPartner'}});
			}
		}

		$scope.radio.type = type;
		$scope.radio.code = code;
		$scope.radio.subIndex = subIndex;
		if(modalKey == undefined || modalKey == null || modalKey == '') {
			layer.msg('单选弹出框KEY值尚未配置');
			return;
		}
		if(type == 2 && (subIndex == undefined || subIndex == null)) {
			layer.msg('子列表所在行号尚未配置');
			return;
		}
		$scope.radio.bsObj = new bootstrap.Modal(document.getElementById('modal_radio'), {
			keyboard: false
		});

		var res = MAP_MODAL[modalKey];
		console.log(modalKey);
		console.log(res);
		$scope.radio.conditions = res.conditions; // 查询条件数组
		// 处理默认条件
		if(conditionsDefault) {
			for (var i = 0; i < conditionsDefault.length; i++) {
				var conditionDefault = conditionsDefault[i];
				for (var j = 0; j < $scope.radio.conditions.length; j++) {
					if (conditionDefault['code'] == $scope.radio.conditions[j]['code']) {
						$scope.radio.conditions[j]['value'] = conditionDefault['value'];
					}
				}
			}
		}

		$scope.radio.colArr = res.colGrids; // 字段数组
		$scope.radio.pathGridRequest = res.pathGridRequest; // 弹出框数据请求路径
		$scope.radio.loadModalRadioGrid(1);

		$scope.radio.bsObj.show();
	};


	$scope.doSelectRadioBySelf = function(data) {
		console.log('单选框特殊回调---doSelectRadioBySelf---', data);

		if($scope.valueMap["accountType"] == '0') {//员工账户
			$scope.valueMap["userBankInfoId"] = data.id;
			$scope.valueMap["partnerBankInfoId"] = '';
			$scope.valueMap["_ys_vyhzhmc"] = data.vyhzhmc;
			$scope.valueMap["_ys_vkhh"] = data.vkhh;
			$scope.valueMap["_ys_vyhzh"] = data.vyhzh;
			$scope.valueMap["accountTypeByModal"] = 0;
		}else{//合作商账户
			$scope.valueMap["partnerBankInfoId"] = data.id;
			$scope.valueMap["userBankInfoId"] = '';
			$scope.valueMap["_ys_vyhzhmc"] = data.vyhzhmc;
			$scope.valueMap["_ys_vkhh"] = data.vkhh;
			$scope.valueMap["_ys_vyhzh"] = data.vyhzh;
			$scope.valueMap["accountTypeByModal"] = 1;
		}
	}

}])